package com.ming.springcloud.consumer.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.ming.springcloud.consumer.service.StudentService;
import com.ming.springcloud.consumer.service.UserService;
import com.ming.springcloud.consumer.util.ResponseEntity;
import com.ming.springcloud.consumer.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @ResponseBody
    @PostMapping("/login")
    public ResponseEntity login(String userAccount , String userPassword){
        System.out.println("userAccount=="+userAccount+"--->userPassword=="+userPassword);

        String urls="urls";

        User user = new User();
        user.setUserAccount(userAccount);
        user.setUserPassword(userPassword);
       String josn= userService.login("ming",user);

        JSONObject object = (JSONObject) JSONObject.parse(josn);
        Integer result =Integer.parseInt(object.get("code").toString());
        if (result!=1){

            System.out.println("登录失败！！");
            return  ResponseEntity.error("登录失败");
        }
        return  ResponseEntity.success().add("urls",urls);
    }
}
